<template>
    <div ref="chartRef" class="bar-chart"></div>
</template>

<script setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import echarts from '@/utils/echart';

const chartRef = ref(null);
let chartObj = null;
const resize = () => {
    chartObj.resize();
};
const init = () => {
    chartObj = echarts.init(chartRef.value);
    const option = {
        tooltip: {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                data: [120, 200, 150, 80, 70, 110, 130],
                type: 'bar'
            }
        ]
    };
    chartObj.setOption(option);
    window.addEventListener('resize', resize);
};
onMounted(() => {
    init();
});
onBeforeUnmount(() => {
    window.addEventListener('resize', resize);
});
</script>
<style lang="less" scoped>
.bar-chart {
    width: 100%;
    height: 100%;
}
</style>
